package com.hqyj.ctxp.controller;

import com.hqyj.ctxp.pojo.OrderItem;
import com.hqyj.ctxp.service.OrdersService;
import com.hqyj.ctxp.utils.PageBean;
import com.hqyj.ctxp.utils.ResultInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/api/orders")
public class OrdersController {

    @Autowired
    private OrdersService ordersService;

    // 127.0.0.1:8888/api/orders/addOrder/{totalPrice}-- delete
    // 结算 增加订单
    @PutMapping("/addOrder/{userNo}/{totalPrice}")
    public ResultInfo addOrder(@PathVariable Integer userNo, @PathVariable Double totalPrice, @RequestBody List<OrderItem> orderItems) {
        ResultInfo resultInfo = ordersService.addOrder(userNo, totalPrice, orderItems);
        return resultInfo;
    }

    // 127.0.0.1:8888/api/orders/deleteOrderById/{orderNo} -- delete
    // 用户根据订单编号删除订单
    @DeleteMapping("/deleteOrderById/{orderNo}")
    public ResultInfo deleteOrderById(@PathVariable Integer orderNo) {
        ResultInfo resultInfo = ordersService.deleteOrderById(orderNo);
        return resultInfo;
    }

    // 127.0.0.1:8888/api/orders/deleteOrderByIdAdmin/{orderNo} -- delete
    // 管理员根据订单编号删除订单
    @DeleteMapping("/deleteOrderByIdAdmin/{orderNo}")
    public ResultInfo deleteOrderByIdAdmin(@PathVariable Integer orderNo) {
        ResultInfo resultInfo = ordersService.deleteOrderByIdAdmin(orderNo);
        return resultInfo;
    }

    // 127.0.0.1:8888/api/orders/selectOrderPage -- post
    // 查询 所有用户订单
    @PostMapping("/selectOrderPage")
    public ResultInfo selectOrderPage(@RequestBody PageBean pageBean) {
        ResultInfo resultInfo = ordersService.selectOrderPage(pageBean);
        return resultInfo;
    }


    // 127.0.0.1:8888/api/orders/selectOrders/{userNo} -- get
    // 查询 当前用户订单
    @GetMapping("/selectOrders/{userNo}")
    public ResultInfo selectOrders(@PathVariable Integer userNo) {
        ResultInfo resultInfo = ordersService.selectOrders(userNo);
        return resultInfo;
    }

    // 127.0.0.1:8888/api/orders/submitOrder/{orderNo} -- put
    // 提交订单 修改订单状态
    @PutMapping("/submitOrder/{orderNo}/{userNo}")
    public ResultInfo submitOrder(@PathVariable Long orderNo, @PathVariable Integer userNo) {
       ResultInfo resultInfo = ordersService.submitOrder(orderNo, userNo);
       return resultInfo;
    }

    // 127.0.0.1:8888/api/orders/submitOrderAdmin/{orderNo}/{userNo} -- put
    // 管理员发货 修改订单状态
    @PutMapping("/submitOrderAdmin/{orderNo}/{userNo}")
    public ResultInfo submitOrderAdmin(@PathVariable Long orderNo, @PathVariable Integer userNo) {
        ResultInfo resultInfo = ordersService.submitOrderAdmin(orderNo, userNo);
        return resultInfo;
    }
}
